#!/bin/bash

# 设置应用名称和 Jar 包路径
APP_NAME="stock-0.0.1-SNAPSHOT.jar"
JAR_PATH="/root/stock/$APP_NAME"

# 检查 Jar 包是否存在
if [ ! -f "$JAR_PATH" ]; then
    echo "Error: $APP_NAME not found"
    exit 1
fi

# 查找应用的进程 ID
PID=$(ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}')
# 检查进程是否存在
if [ -z "$PID" ]; then
    echo "$APP_NAME is not running"
else
    # 杀死进程
    kill -9 $PID
    echo "$APP_NAME stopped successfully"
fi

# 启动应用
nohup java -jar $JAR_PATH &
echo "$APP_NAME started successfully"
